package com.batchbrake.queue.actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

import com.batchbrake.main.BatchBrake;
import com.batchbrake.main.BatchBrakeFrame;
import com.batchbrake.main.EFile;
import com.batchbrake.queue.QueueBuilder;

public class SetOutputFolderAction extends AbstractAction {
	private BatchBrakeFrame frame = null;
	
	public SetOutputFolderAction(BatchBrakeFrame frame) {
		super("Set output folder");
		this.frame = frame;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		JFileChooser dialog = new JFileChooser();
		FileNameExtensionFilter filter = new FileNameExtensionFilter("Movies", QueueBuilder.inputFormats);
		
		dialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		dialog.setDialogTitle("Select the output folder");
		dialog.setMultiSelectionEnabled(false);
		dialog.setFileFilter(filter);
		dialog.setSize(700, 500);
		
		dialog.setCurrentDirectory(BatchBrake.outputFolder);
		int result = dialog.showOpenDialog(null);
		switch( result ) {
		case JFileChooser.APPROVE_OPTION:
			BatchBrake.outputFolder = new EFile(dialog.getSelectedFile().getAbsolutePath());
			frame.lblOutputFolder.setText("<html><b>Output folder : </b>" + BatchBrake.outputFolder);
			frame.lblOutputFolder.repaint();
		case JFileChooser.CANCEL_OPTION:
		case JFileChooser.ERROR_OPTION:
			dialog.setVisible(false);
		}
	}
}
